from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
from math import *
from glturtle import *

phase = 0
from time import *
from clock import *
import colors #<----- problem is here

color_palette1 = {\
                        'ticks': ('digits'),\
                        'digits': 'RED',\
                        'square': (0, 0, 1),\
                        'h-arrow': (0, 1, 1),\
                        'm-arrow': (1, 1, 1),\
                        'seconds': (0, 1, 0),\
                        'semicolon': (.8, 0, .5)}

color_palette2 = {\
                        'ticks': 'square',\
                        'digits': 'h-arrow',\
                        'square': 'rady',\
                        'h-arrow': 'SUNY',\
                        'm-arrow': 'bla',\
                        'seconds': (1, 1, 1),\
                        'semicolon': (1, .5, .5)}

'''my_clock = Clock(0, .4, -.6, .6)
my_clock2 = Clock(1.5, .4, .6, .6)
my_clock3 = Clock(-1, .4, -.6, -.6)
clock_instance = Clock(0, .5, -.6, .6)'''

#print "color_palette2 before:"+"\n".join(["\t"+k+":"+str(v) for k,v in color_palette2.items()])

clock_mas = [Clock(0, .5, -.6, .6, False, color_palette2), Clock(1.5, .4, .6, .6, False, color_palette1), Clock(-1, .2, -.6, -.6, True, color_palette2)]

#print "color_palette2 after:"+"\n".join(["\t"+k+":"+str(v) for k,v in color_palette2.items()])

def init():
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glClearDepth(1.0)
    glDepthFunc(GL_LEQUAL)
    glEnable(GL_DEPTH_TEST)
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)


def reshape(width, height):
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(-1, 1, -1, 1, -1, 1)


def display():
    try:
        '''global my_clock
        global my_clock2
        global my_clock3'''

        global clock_mas
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glPushMatrix()

        '''my_clock.draw()
        my_clock2.draw()
        my_clock3.draw()'''
 
        for i in clock_mas:
            i.draw()
        

        glPopMatrix()
        glutSwapBuffers()

    except:
        print "Error:", sys.exc_info()
        sys.exit()


def keyPressed(*args):
    # global object, reflMode

    key = args[0]
    if key == '\033':  # ESC
        sys.exit()


"""	elif key == 'n' or key == 'N':
        reflMode = GL_NORMAL_MAP_ARB
    elif key == 'r' or key == 'R':
        reflMode = GL_REFLECTION_MAP_ARB
    elif key == '0':
        object = 0
    elif key == '1':
        object = 1
    elif key == '2':
        object = 2
    elif key == '3':
        object = 3
    elif key == '4':
        object = 4
    elif key == '5':
        object = 5
    elif key == '6':
        object = 6
    elif key == '7':
        object = 7
    elif key == '8':
        object = 8
    elif key == '+':
        object = object + 1
        if object > 8:
            object = 0
    elif key == '-':
        object = object-1
        if object < 0:
            object = 8
"""


def animate():
    global phase
    phase += 1
    glutPostRedisplay()


def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
    glutInitWindowSize(500, 500)
    glutInitWindowPosition(200, 200)

    glutCreateWindow("ARB_texture_cubemap demo")
    glutDisplayFunc(display)
    glutIdleFunc(animate)
    glutReshapeFunc(reshape)
    glutKeyboardFunc(keyPressed)

    init()
    glutMainLoop()


print "Hit ESC key to quit."
main()

